home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / mtl100je.zip / EXAMPLE1.CPP < prev    next >
C/C++ Source or Header  |  1993-05-06  |  2KB  |  62 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //      EXAMPLE1.CPP: example for DOS multithreading library.
  4. //      Copyright (c) J.English 1993.
  5. //      Author's address: je@unix.brighton.ac.uk
  6. //
  7. //      Permission is granted to use copy and distribute the
  8. //      information contained in this file provided that this
  9. //      copyright notice is retained intact and that any software
  10. //      or other document incorporating this file or parts thereof
  11. //      makes the source code for the library of which this file
  12. //      is a part freely available.
  13. //
  14. //--------------------------------------------------------------------------
  15. //
  16. //      This example starts 3 identical threads, each of which repeatedly
  17. //      displays a message and then pauses.
  18. //
  19. //--------------------------------------------------------------------------
  20.  
  21. #include <stdio.h>
  22. #include <conio.h>
  23. #include "threads.h"
  24.  
  25. class Example1 : public DOSThread
  26. {
  27.   public:
  28.     Example1 (int n)      { num = n; }
  29.  
  30.   protected:
  31.     virtual void main ();
  32.  
  33.   private:
  34.     int num;
  35. };
  36.  
  37. void Example1::main ()
  38. {
  39.     char c [70];
  40.     sprintf (c, "Thread %d\n", num);
  41.     while (!userbreak())
  42.     {   fputs (c, stdout);
  43.         pause ();
  44.     }
  45. }
  46.  
  47. void main ()
  48. {
  49.     Example1 e1 (1), e2 (2), e3 (3);
  50.  
  51.     puts ("Press CONTROL-BREAK to terminate");
  52.     puts ("Press any key to start...");
  53.     getch ();
  54.  
  55.     if (!e1.run ())
  56.         puts ("Couldn't start thread 1");
  57.     if (!e2.run ())
  58.         puts ("Couldn't start thread 2");
  59.     if (!e3.run ())
  60.         puts ("Couldn't start thread 3");
  61. }
  62.